package com.douxg.fastCoding.spring.config;

import com.baomidou.mybatisplus.extension.plugins.tenant.TenantHandler;
import lombok.SneakyThrows;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Column;

/**
 * @Description
 * @Auther douxg
 * @Date 2021/4/20 10:54
 */
public class MyOrgHandler implements TenantHandler {
    @SneakyThrows
    @Override
    public Expression getTenantId(boolean where) {
        Expression expression = CCJSqlParserUtil.parseCondExpression("ORG_ID IN (1,2)");
        InExpression inExpression = new InExpression();
//        inExpression.setLeftExpression(new Column("ORG_ID"));
        inExpression.setRightItemsList(new ExpressionList(new LongValue(1), new LongValue(2)));
        return inExpression;
    }

    @Override
    public String getTenantIdColumn() {
        return "ORG_ID";
//        return null;
    }

    @Override
    public boolean doTableFilter(String tableName) {
        return false;
    }
}
